import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item);

	public Integer pop();

	public Integer peek();

	public boolean empty();

	public int size();
}

class ArrayIntegerStack implements IntegerStack {
	private List<Integer> list;

	public ArrayIntegerStack() {
		list = new ArrayList<Integer>();
	}

	@Override
	public Integer push(Integer item) {
		if (item == null)
			return null;
		list.add(item);
		return item;

	}

	@Override
	public Integer pop() {
		if (list.size() == 0)
			return null;
		return list.remove(list.size()-1);
	}

	@Override
	public Integer peek() {
		if (list.size() == 0)
			return null;
		return list.get(list.size()-1);
	}

	@Override
	public boolean empty() {
		return size() == 0;
	}

	@Override
	public int size() {
		return list.size();
	}

	public Integer[] getStack() {
		Integer[] array = (Integer[])list.toArray(new Integer[list.size()]); 
		return array;
	}

	@Override
	public String toString() {
		return list.toString();
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		ArrayIntegerStack stack = new ArrayIntegerStack();
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			System.out.println(stack.push(in.nextInt()));
		}
		System.out.print(stack.peek() + "," + stack.empty() + "," + stack.size() + "\n");
		System.out.println(Arrays.toString(stack.getStack()));
		int x = in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(stack.pop());
		}
		System.out.print(stack.peek() + "," + stack.empty() + "," + stack.size() + "\n");
		System.out.println(Arrays.toString(stack.getStack()));
		in.close();
	}
}